<?php
    require_once ("script.php");
    require_once ("script2.php");
    

?>
<body>
<?php
    if($_GET['actiune'] == "sterge"){
        $sql = 'DELETE FROM filetype WHERE
                    Id = ' . $_GET["id"];
        $res = mysql_query($sql);
    }

    if($_GET['actiune'] == "adaugare"){
        $sql = 'INSERT INTO filetype SET
                    Name = "' . $_GET["Name"] . '",
                    Extension = "' . $_GET["Extension"] . '",
                    CreateDate = "' . date('y-m-d H:i:s') . '",
                    Ip = "' . $_SERVER['REMOTE_ADDR']  .'"';
        $res = mysql_query($sql);
    }

    if($_GET['pagina'] == "adaugare"){
        ?>
    <form name='form1' enctype='multipart/form-data' method='get' action='addFileType.php'>
        Nume: 
        <input id='Name' type='text' name='Name'>
        <br/>
        Extensie: .
        <input id='Extension' type='text' name='Extension'>
        <br/>
        <input name='actiune' type='hidden' value='adaugare'>
        <input type='submit' value='Ad&#259;ugare' name='Submit' role='button' aria-disabled='false'>
        <INPUT TYPE=BUTTON VALUE='&Icirc;napoi' CLASS=b ONCLICK='window.location="addFileType.php"'>
        
    </form>
        <?php
    }
    if(!$_GET['pagina']){
?>
    <a href="addFileType.php?pagina=adaugare"><button type="button">Adaugare</button></a>
<?php
        $sql = 'SELECT * FROM filetype';
        $req = mysql_query($sql);
        echo "<table class='fancy3'>";
        echo "<tr>
                <th>Name</th>
                <th>Extension</th>
                <th>Options</th>
            </tr>";     
        while ($res = mysql_fetch_array($req)){
         echo "<tr>";
            echo "<td>";
                echo $res['Name'];
            echo "</td>";
            echo "<td>";
                echo "." . $res['Extension'];
            echo "</td>";
            echo "<td>";
                echo "<a href = 'addFileType.php?id=" . $res["Id"] . "&actiune=sterge'><img src='images/cross.png' alt='sterge'/></a>";             
            echo "</td>";
          echo "</tr>";
        }     
        echo "</table>";
        echo "<INPUT TYPE=BUTTON VALUE='&Icirc;napoi' CLASS=b ONCLICK='window.location=\"index.php\";'>";
    }
?>
</body>
